home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Complete Applications / Telecom / MT Special 3 / IBM WWIV / COMMON.PAS next >
Encoding:
Pascal/Delphi Source File  |  1987-01-14  |  23.3 KB  |  968 lines  |  [TEXT/ttxt]

  1.  
  2. function cs:boolean;
  3. begin
  4.   cs:=cosysop in seclev[thisuser.sl].anst;
  5. end;
  6.  
  7. function so:boolean;
  8. begin
  9.   so:=thisuser.sl=255;
  10. end;
  11.  
  12. function lcs:boolean;
  13. begin
  14.   lcs:=cs or ((lcosysop in seclev[thisuser.sl].anst) and ((board=thisuser.sbn) or (thisuser.sbn=0)));
  15. end;
  16.  
  17. function commpressed : boolean;
  18. begin
  19.  commpressed := (buffer_tail<>buffer_head);
  20. end;
  21.  
  22. procedure dump;
  23. begin
  24.   inline($FA);
  25.   buffer_head:=0;
  26.   buffer_tail:=buffer_head;
  27.   inline($FB);
  28. end;
  29.  
  30. procedure async_isr;
  31. begin
  32.   inline($50/$53/$52/$1E/$FB/$2E/$FF/$36/dsaves/$1F/$8B/$16/base/
  33.          $EC/$8B/$1E/buffer_Head/$88/$87/buffer/$43/$81/$FB/buffer_Max/$7E/
  34.          $02/$33/$DB/$3B/$1E/buffer_Tail/$74/$04/$89/$1E/buffer_Head/$FA/
  35.          $B0/$20/$E6/$20/$1F/$5A/$5B/$58/$5C/$5D/$CF);
  36. end;
  37.  
  38. procedure remove_port;
  39. var
  40.   i,m:integer;
  41. begin
  42.   inline($FA);
  43.   i := port[$21];
  44.   m := 1 shl Async_Irq;
  45.   port[$21] := i or m;
  46.   port[2+base] := 0;
  47.   port[4+base] := 1;
  48.   inline($FB);
  49. end;
  50.  
  51. procedure term_ready(s:Boolean);
  52. var x:byte;
  53. begin
  54.   x := port[4+base] and $FE;
  55.   if s then x:=x+1;
  56.   port[4+base] := x;
  57. end;
  58.  
  59. procedure set_baud(r:integer);
  60. var rl:real; a:byte;
  61. begin
  62.   if (r>=300) and (r<=9600) then begin
  63.     rl:=115200.0/r;
  64.     r:=trunc(rl);
  65.     a:=port[3+base] or 128;
  66.     port[base+3]:=a;
  67.     port[base]:=lo(r);
  68.     port[1+base]:=hi(r);
  69.     port[3+base]:=a and 127;
  70.   end;
  71. end;
  72.  
  73.  
  74. procedure iport;
  75. var
  76.    i,m:Integer;
  77.    regs:record ax,bx,cx,dx,bp,si,di,ds,es,flags:integer; end;
  78. begin
  79.   dsaves:= DSeg;
  80.   If ComPort = 2 Then begin
  81.     base := $2f8;
  82.     Async_Irq  := 3;
  83.   end else begin
  84.     base := $3f8;
  85.     Async_Irq  := 4;
  86.   end;
  87.   If (Port[2+base] and $00F8) <> 0 Then
  88.     begin writeln('Illegal com port number'); halt; end
  89.   else begin
  90.     buffer_Head:=0; buffer_Tail:=0; port[base+3]:=$03;
  91.     with regs do begin
  92.       ax:=$2500+((async_irq+8) and $00ff); ds:=cseg;
  93.       dx:=ofs(async_isr); msdos(regs);
  94.     end;
  95.     inline($FA);
  96.     i:=port[5+base];
  97.     i:=port[base];
  98.     i:=port[$21];
  99.     m:=(1 shl Async_Irq) xor $00FF;
  100.     port[$21] := i and m;
  101.     port[1+base] := $01;
  102.     i := port[4+base];
  103.     port[4+base] := i or $08;
  104.     term_ready(true);
  105.     inline($FB);
  106.   end;
  107. end;
  108.  
  109. function cinkey:char;
  110. var t:char;
  111. begin
  112.   if buffer_Head = buffer_Tail Then
  113.     t:=#0
  114.   else begin
  115.     inline($FA);
  116.     t:=buffer[buffer_Tail];
  117.     buffer_Tail:=(buffer_Tail+1) mod (buffer_max+1);
  118.     inline($FB);
  119.   end;
  120.   cinkey:=chr(ord(t) and 127);
  121. end;
  122.  
  123. function cinkey1:char;
  124. var t:char;
  125. begin
  126.   if buffer_Head = buffer_Tail Then
  127.     t:=#0
  128.   else begin
  129.     inline($FA);
  130.     t:=buffer[buffer_Tail];
  131.     buffer_Tail:=(buffer_Tail+1) mod (buffer_max+1);
  132.     inline($FB);
  133.   end;
  134.   cinkey1:=t;
  135. end;
  136.  
  137. procedure o1(c:char);
  138. begin
  139.   while (port[base+5] and 32)=0 do;
  140.   port[base]:=ord(c);
  141. end;
  142.  
  143. procedure o(c:char);
  144. begin
  145.   if outcom and (c<>#1) then o1(c);
  146. end;
  147.  
  148. FUNCTION TIMER: REAL;
  149.  
  150. VAR REG: RECORD
  151.            AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: INTEGER;
  152.          END;
  153.     H,M,S,T: REAL;
  154.  
  155. BEGIN
  156.   REG.AX := 44 * 256;
  157.   MsDos(REG);
  158.   H      := (REG.CX DIV 256);
  159.   M      := (REG.CX MOD 256);
  160.   S      := (REG.DX DIV 256);
  161.   T      := (REG.DX MOD 256);
  162.   TIMER  := H*3600 + M*60 + S + T/100;
  163. END;
  164.  
  165. function sysop1:boolean;
  166. begin
  167.   if (mem[0:1047] and 16)=0 then sysop1:=false else sysop1:=true;
  168. end;
  169.  
  170. function sysop:boolean;
  171. begin
  172.   sysop:=sysop1;
  173.   if rchat in thisuser.ac then sysop:=false;
  174. end;
  175.  
  176. procedure bs;
  177. var x,y:integer;
  178. begin
  179.   x:=wherex; y:=wherey; if x>1 then x:=x-1 else
  180.     if y>1 then begin x:=80; y:=y-1; end;
  181.   gotoxy(x,y);
  182. end;
  183.  
  184. procedure backs;
  185. begin
  186.   o(chr(8)); bs; write(' '); o(' '); o(chr(8)); bs;
  187. end;
  188.  
  189. procedure sl1(i:str);
  190. begin
  191.   if (realsl<>255) or incom then begin
  192.     assign(sysopf,'gfiles\sysop.log'); {$I-} append(sysopf);{$I+}
  193.     if ioresult<>0 then
  194.       rewrite(sysopf);
  195.     writeln(sysopf,i);
  196.     close(sysopf);
  197.   end;
  198. end;
  199.  
  200. procedure sysoplog(i:str);
  201. begin
  202.   sl1('   '+i);
  203. end;
  204.  
  205. function tch(i:str):str;
  206. begin
  207.   if length(i)>2 then i:=copy(i,length(i)-1,2) else
  208.     if length(i)=1 then i:='0'+i;
  209.   tch:=i;
  210. end;
  211.  
  212. FUNCTION TIME:STR;
  213. VAR REG: RECORD
  214.            AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: INTEGER;
  215.          END;
  216.     H,M,S:string[4];
  217. BEGIN
  218.   reg.ax:=$2c00; intr($21,reg);
  219.   str(reg.cx shr 8,h); str(reg.cx mod 256,m); str(reg.dx shr 8,s);
  220.   time:=tch(h)+':'+tch(m)+':'+tch(s);
  221. END;
  222.  
  223. FUNCTION DATE:STR;
  224. VAR REG: RECORD
  225.            AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: INTEGER;
  226.          END;
  227.     M,D,Y:STRing[4];
  228. BEGIN
  229.   reg.ax:=$2a00; msdos(reg); str(reg.cx,y); str(reg.dx mod 256,d);
  230.   str(reg.dx shr 8,m);
  231.   date:=tch(m)+'/'+tch(d)+'/'+tch(y);
  232. END;
  233.  
  234. FUNCTION value(I:str):INTEGER;
  235. VAR N,N1:INTEGER;
  236. BEGIN
  237.   VAL(I,N,N1);
  238.   IF N1<>0 THEN BEGIN
  239.     I:=COPY(I,1,N1-1);
  240.     VAL(I,N,N1)
  241.   END;
  242.   VaLue:=N;
  243.   if i='' then value:=0;
  244. END;
  245.  
  246.  
  247. function cstr(i:integer):str;
  248. var c:str;
  249. begin
  250.   str(i,c); cstr:=c;
  251. end;
  252.  
  253. function nam:str;
  254. var s:str; i:integer; tf:boolean;
  255. begin
  256.   s:=thisuser.name;
  257.   tf:=true;
  258.   for i:=1 to length(s) do
  259.     if s[i]<'A' then
  260.       tf:=true
  261.     else begin
  262.       if (s[i]<='Z') and not tf then
  263.         s[i]:=chr(ord(s[i])+32);
  264.       tf:=false;
  265.     end;
  266.   nam:=s+' #'+cstr(usernum);
  267. end;
  268.  
  269.  
  270. function leapyear(yr:integer):boolean;
  271. begin
  272.   leapyear:=(yr mod 4=0) and ((yr mod 100<>0) or (yr mod 400=0));
  273. end;
  274.  
  275. function days(mo,yr:integer):integer;
  276. var d:integer;
  277. begin
  278.   d:=value(copy('312831303130313130313031',1+(mo-1)*2,2));
  279.   if (mo=2) and leapyear(yr) then d:=d+1;
  280.   days:=d;
  281. end;
  282.  
  283. function daycount(mo,yr:integer):integer;
  284. var m,t:integer;
  285. begin
  286.   t:=0;
  287.   for m:=1 to (mo-1) do t:=t+days(m,yr);
  288.   daycount:=t;
  289. end;
  290.  
  291. function daynum(dt:str):integer;
  292. var d,m,y,t,c:integer;
  293. begin
  294.   t:=0;
  295.   m:=value(copy(dt,1,2));
  296.   d:=value(copy(dt,4,2));
  297.   y:=value(copy(dt,7,2))+1900;
  298.   for c:=1985 to y-1 do
  299.     if leapyear(c) then t:=t+366 else t:=t+365;
  300.   t:=t+daycount(m,y)+(d-1);
  301.   daynum:=t;
  302.   if y<1985 then daynum:=0;
  303. end;
  304.  
  305. function dat:str;
  306. var ap,x,y:str; i:integer;
  307. begin
  308.   case daynum(date) mod 7 of
  309.     0:x:='Tue';
  310.     1:x:='Wed';
  311.     2:x:='Thu';
  312.     3:x:='Fri';
  313.     4:x:='Sat';
  314.     5:x:='Sun';
  315.     6:x:='Mon';
  316.   end;
  317.   case value(copy(date,1,2)) of
  318.     1:y:='Jan';
  319.     2:y:='Feb';
  320.     3:y:='Mar';
  321.     4:y:='Apr';
  322.     5:y:='May';
  323.     6:y:='Jun';
  324.     7:y:='Jul';
  325.     8:y:='Aug';
  326.     9:y:='Sep';
  327.     10:y:='Oct';
  328.     11:y:='Nov';
  329.     12:y:='Dec';
  330.   end;
  331.   x:=x+' '+y+' '+copy(date,4,2)+', '+cstr(1900+value(copy(date,7,2)));
  332.   y:=time; i:=value(copy(y,1,2));
  333.   if i>11 then ap:='pm' else ap:='am';
  334.   if i>12 then i:=i-12;
  335.   if i=0 then i:=12;
  336.   dat:=cstr(i)+copy(y,3,3)+' '+ap+'  '+x;
  337. end;
  338.  
  339. procedure checkhangup;
  340. begin
  341.   if incom and ((port[base+6] and 128)=0) and (not hangup) then begin
  342.     hangup:=true; hungup:=true;
  343.   end;
  344. end;
  345.  
  346. Procedure topscr; forward;
  347.  
  348. procedure getkey(var c:char); forward;
  349.  
  350. procedure pr(i:str);
  351. var c:integer;
  352. begin
  353.   i:=i+#13;
  354.   for c:=1 to length(i) do o1(i[c]);
  355. end;
  356.  
  357. procedure prompt(i:str);
  358. var c:integer; cc:char;
  359. begin
  360.  checkhangup;
  361.  if not hangup then begin
  362.   for c:=1 to length(i) do begin
  363.     if (not ((i[c]=chr(7)) and (incom))) and (i[c]<>chr(12)) and (i<>#1) then write(i[c]);
  364.     if chatcall then sound(1000);
  365.     o(i[c]);
  366.     if i[c]>#31 then thisline:=thisline+i[c];
  367.     if i[c]=#8 then if length(thisline)>0 then thisline:=copy(thisline,1,length(thisline)-1);
  368.     if i[c]=chr(12) then begin lil:=0; clrscr; topscr; end;
  369.     if i[c]=chr(13) then begin pap:=0; thisline:=''; end;
  370.     nosound;
  371.     if i[c]=chr(10) then begin
  372.       lil:=lil+1;
  373.       if (lil>=thisuser.pagelen-1) then begin
  374.         lil:=0;
  375.         if pause in thisuser.defaults then begin
  376.           prompt('(-*-)');
  377.           getkey(cc); prompt(' '+chr(8));
  378.           for cc:='A' to 'E' do
  379.             prompt(chr(8)+' '+chr(8));
  380.         end;
  381.       end;
  382.     end;
  383.   end;
  384.  end;
  385. end;
  386.  
  387. procedure print(i:str);
  388. begin
  389.   prompt(i+chr(13)+chr(10))
  390. end;
  391.  
  392.  
  393. procedure nl;
  394. begin
  395.   prompt(chr(13)+chr(10))
  396. end;
  397.  
  398. procedure tleft;
  399. var x,y:integer;
  400. begin
  401.  if okt then begin
  402.   x:=wherex; y:=wherey; window(1,1,80,4);
  403.   gotoxy(72,3);if chatcall then begin
  404.     write('CHAT ON');
  405.     if alert in thisuser.option then begin
  406.       gotoxy(72,3);
  407.       write('ALERT  ');
  408.     end;
  409.   end else write('       ');
  410.   gotoxy(56,3); if sysop1 then write('Sysop Available') else
  411.     write('----- ---------');
  412.   if useron then begin
  413.     gotoxy(35,3); if thisuser.ontoday<>1 then write('ML=',extramsgs+seclev[thisuser.sl].mallowed-mread,'   ');
  414.     gotoxy(45,3); write('TL=',((seclev[thisuser.sl].ttime*60+extratime+timeon-timer)/60):6:2,'  ');
  415.   end;
  416.   if hangup then begin
  417.     gotoxy(72,3);
  418.     write('HANG UP');
  419.   end;
  420.   window(1,5,80,25);gotoxy(x,y);
  421.   if timer<timeon then timeon:=timeon-24.0*60*60;
  422.   if not ch and ((seclev[thisuser.sl].ttime*60+extratime+timeon-timer)<0) and useron then
  423.   begin nl; print('Time expired.'); hangup:=true; end;
  424.   checkhangup;
  425.  end;
  426. end;
  427.  
  428.  
  429. procedure prestrict(u:userrec);
  430. var r:restrictions;
  431. begin
  432.   for r:=rlogon to rmsg do
  433.     if r in u.ac then write(copy('LCVBA*PEKM',ORD(R)+1,1)) else write(' ');
  434.   writeln;
  435. end;
  436.  
  437. procedure ff(i:integer);
  438. begin
  439.   while wherex<i do write(' ');
  440. end;
  441.  
  442. procedure topscr;
  443. var c:char; x,y,i:integer;
  444. begin
  445.  if (usernum<>0) and okt then begin
  446.   x:=wherex; y:=wherey;
  447.   window(1,1,80,5);
  448.   gotoxy(1,1); write(chr(186),' ',nam); ff(35);
  449.   with thisuser do begin
  450.     write(realname);ff(50);write(ph);ff(65);
  451.     if laston<>date then write(laston);
  452.     ff(76); if date=laston then write(ontoday); ff(79);
  453.     write(' ',chr(186));gotoxy(1,2);
  454.     write(chr(186),' SL=',sl);ff(10);write('AR=');
  455.     for c:='A' to 'G' do if c in ar then write(c) else write(' ');
  456.     write(' LO=',loggedon);
  457.     ff(28);write('P=',msgpost);ff(35);write('E=',emailsent);
  458.     ff(42);write('F=',feedback);ff(48);
  459.     write('W=',waiting);ff(54);
  460.     if not useron then write('"',pw,'"') else write('SC=',thisuser.linelen,'X',
  461.       thisuser.pagelen,'   ');
  462.     ff(68);write('FW=',fw); ff(74); write('D=',thisuser.dsl);
  463.     gotoxy(80,2);write(#186);
  464.     gotoxy(1,3);write(#186,' AC='); prestrict(thisuser);
  465.     gotoxy(17,3);write('C=',comptyp[thisuser.comptype]);
  466.     gotoxy(80,3);write(chr(186));
  467.     gotoxy(1,4);write(chr(200));
  468.     for i:=2 to 79 do
  469.       write(chr(205));
  470.     write(chr(188));
  471.   end;
  472.   window(1,5,80,25);gotoxy(x,y);
  473.   tleft;
  474.  end;
  475. end;
  476.  
  477. function empty:boolean;
  478. begin
  479.   if incom then empty:=not commpressed else empty:=true;
  480.   if keypressed then empty:=false;
  481.   if hangup then begin dump; empty:=true; end;
  482. end;
  483.  
  484. function inkey:char;
  485. var c:char;
  486. begin
  487.   c:=chr(0); inkey:=chr(0);
  488.   if keypressed then begin
  489.     read(kbd,c); if c=chr(27) then
  490.       if keypressed then begin
  491.         read(kbd,c);
  492.         c:=chr(ord(c) or 128);
  493.       end;
  494.     inkey:=c;
  495.   end else begin
  496.     if commpressed and incom then begin
  497.       inkey:=cinkey;
  498.     end;
  499.   end;
  500. end;
  501.  
  502. procedure oc(c:char);
  503. begin
  504.   if c=chr(8) then bs else if c<>chr(0) then write(C);
  505.   o(c);
  506. end;
  507.  
  508. procedure outkey(c:char);
  509. begin
  510.   if (c<>chr(12)) and (not ((c=chr(7)) and (incom))) then if c=chr(8) then bs else if c<>#0 then write(c);
  511.   if (not echo) and (c>=' ') then c:='X';
  512.   o(c);
  513.   if c=chr(12) then begin clrscr; topscr; end;
  514.   if c=#7 then begin o(#0); o(#0); o(#0); o(#0); end;
  515. end;
  516.  
  517. procedure phelp; forward;
  518.  
  519. procedure getkey;
  520. var p:integer; t:real; tf,t1:boolean;
  521. begin
  522.  if buf<>'' then begin
  523.    c:=buf[1]; buf:=copy(buf,2,length(buf)-1);
  524.  end else if not empty then c:=inkey else begin
  525.  p:=1; t:=timer; t1:=false; tf:=false; lil:=0;
  526.  c:=chr(0);
  527.   while (c=chr(0)) and not hangup do begin
  528.     c:=inkey;
  529.     if empty and (c=chr(0)) then begin
  530.       if (spcsr in thisuser.defaults) then begin
  531.         oc(cursor[p]); t1:=true;
  532.         p:=p+1; if p>length(cursor) then p:=1;
  533.       end;
  534.     end;
  535.     if (timer-t)>180 then begin nl;
  536.       print('Call back later when you are there.');hangup:=true;
  537.       sysoplog('!-!-! TIMEOUT !-!-!');
  538.     end;
  539.     if ((timer-t)>90) and (not tf) then begin tf:=true; outkey(chr(7)); end;
  540.     checkhangup;
  541.   end;
  542. if (spcsr in thisuser.defaults) and t1 then begin
  543.  if (p mod 2)=0 then
  544.    oc(chr(8));
  545.  if (c<' ') or (c>=chr(127)) then begin oc(' '); oc(chr(8)); end;
  546. end;
  547. end;
  548. if c=chr(127) then c:=chr(8);
  549. if c=chr(3) then if spcsr in thisuser.defaults then
  550.   thisuser.defaults:=thisuser.defaults-[spcsr] else
  551.    thisuser.defaults:=thisuser.defaults+[spcsr];
  552. if c=chr(3) then c:=chr(0);
  553. if ((c=#6) or (c=#4)) and macok then begin
  554.   if c=#4 then
  555.     buf:=thisuser.macro[1]
  556.   else
  557.     buf:=thisuser.macro[2];
  558.   if buf<>'' then begin c:=buf[1]; buf:=copy(buf,2,length(buf)-1); end;
  559. end;
  560. end;
  561.  
  562. procedure cls;
  563. begin
  564.   outkey(chr(12));
  565. end;
  566.  
  567.  
  568. procedure chsl;
  569. var ij,i:str; c:integer;
  570. begin
  571.  ij:=thisline;
  572.  prompt('[WAIT]');
  573.  writeln;writeln;write('Enter new SL: ');
  574.  readln(i); if i<>'' then thisuser.sl:=value(i); writeln;
  575.  if thisuser.sl=99 then begin
  576.    write('Board #? '); thisuser.sbn:=0;
  577.    readln(i); thisuser.sbn:=value(i);
  578.    writeln;
  579.  end;
  580.  topscr; realsl:=thisuser.sl;
  581.  i:=''; for c:=1 to 6 do i:=i+chr(8)+' '+chr(8);
  582.  prompt(i);
  583.  writeln; thisline:=ij; write(ij);
  584. end;
  585.  
  586. procedure swac(var u:userrec;r:restrictions);
  587. begin
  588.   if r in u.ac then u.ac:=u.ac-[r] else u.ac:=u.ac+[r];
  589. end;
  590.  
  591. procedure acch(c:char; var u:userrec);
  592. begin
  593.   case c of
  594.     'L':swac(u,rlogon);
  595.     'C':SWAC(u,RCHAT);
  596.     'V':SWAC(u,RVALIDATE);
  597.     'B':SWAC(u,RBACKSPACE);
  598.     'A':SWAC(u,RAMSG);
  599.     '*':SWAC(u,RPOSTAN);
  600.     'P':SWAC(u,RPOST);
  601.     'E':SWAC(u,REMAIL);
  602.     'K':SWAC(u,RVOTING);
  603.     'M':swac(u,rmsg);
  604.   END;
  605. end;
  606.  
  607. procedure chac(var thisuser:userrec);
  608. var c:char; ij,i:str; cc:integer;
  609. begin
  610.   ij:=thisline;
  611.   prompt('[WAIT]');
  612.   writeln;writeln('LCVBA*PEKM');writeln;write('Which? '); read(kbd,c); c:=upcase(c); writeln(c); writeln;
  613.   acch(c,thisuser);
  614.   topscr;
  615.   i:=''; for cc:=1 to 6 do i:=i+chr(8)+' '+chr(8);
  616.   prompt(i);
  617.   writeln;
  618.   thisline:=ij; write(ij);
  619. END;
  620.  
  621. procedure chat; forward;
  622.  
  623. procedure chdsl;
  624. var ij,i:str; c:integer;
  625. begin
  626.  ij:=thisline;
  627.  prompt('[WAIT]');
  628.  writeln;writeln;
  629.  writeln('UL=',thisuser.uploads,'-',thisuser.uk,'K   DL=',thisuser.downloads,'-',thisuser.dk,'K');
  630.  write('Enter new DSL: ');
  631.  readln(i); if i<>'' then thisuser.dsl:=value(i); writeln;
  632.  i:=''; for c:=1 to 6 do i:=i+chr(8)+' '+chr(8);
  633.  topscr;
  634.  prompt(i);
  635.  writeln; thisline:=ij; write(ij);
  636. end;
  637.  
  638. procedure tfile;
  639. var i:str; ii:integer;
  640. bf:file of byte; cr:boolean;
  641. begin
  642.   if cfo then begin
  643.     cfo:=false;
  644.     close(cf);
  645.     write('<CLOSED>');
  646.   end else begin
  647.     assign(cf,'gfiles\chat.msg');
  648.     assign(bf,'gfiles\chat.msg'); cr:=false;
  649.     {$I-} reset(bf); {$I+}
  650.     if ioresult<>0 then cr:=true
  651.     else begin
  652.       if filesize(bf)=0 then cr:=true;
  653.       close(bf);
  654.     end;
  655.     if cr then rewrite(cf) else append(cf);
  656.     cfo:=true;
  657.     i:=#13+#10+#13+#10+dat+#13+#10+'==============='+#13+#10;
  658.     writeln(cf,i);
  659.     write('<OPEN>');
  660.   end;
  661. end;
  662.  
  663. procedure skey(c:char);
  664. var b:boolean;
  665. begin
  666.   case ord(c) of
  667.     187:chsl;
  668.     212:chdsl;
  669.     188:chac(thisuser);
  670.     189:begin
  671.          if outcom then incom:=not incom;
  672.          writeln; if incom then writeln('<INPUT ENABLED>')
  673.            else writeln('<COM DISABLED>');
  674.          writeln;dump;
  675.          write(thisline);
  676.        end;
  677.     190:chatcall:=false;
  678.     195:begin
  679.           if thisuser.sl=255 then if realsl<>255 then begin
  680.             thisuser.sl:=realsl; writeln;writeln;writeln('<SECLEV RESTORED>');
  681.             writeln; write(thisline); end
  682.           else else begin
  683.             thisuser.sl:=255; writeln;writeln;writeln('<TEMP SYSOP GRANTED>');
  684.             writeln; write(thisline);
  685.           end; topscr;
  686.         end;
  687.     196:if not ch then chat;
  688.     199:if ch then tfile;
  689.     191:hangup:=true;
  690.     192:tleft;
  691.     193:begin b:=ch; ch:=true; extratime:=extratime-5*60; tleft; ch:=b;end;
  692.     194:begin b:=ch; ch:=true; extratime:=extratime+5*60; tleft; ch:=b;end;
  693.     218:begin b:=ch; ch:=true; extramsgs:=extramsgs-10; tleft; ch:=b;  end;
  694.     219:begin b:=ch; ch:=true; extramsgs:=extramsgs+10; tleft; ch:=b;  end;
  695.   end;
  696.   if (c>chr(127)) and (c<>chr(196)) then c:=chr(0);
  697. end;
  698.  
  699. procedure inli1(var i:str);
  700. var cp:integer; c:char; cv,cc:integer;
  701. begin
  702.   cp:=1;
  703.   i:='';
  704.   if ll<>'' then begin prompt(ll); i:=ll; ll:=''; cp:=length(i)+1;end;
  705.   repeat
  706.     getkey(c); skey(c); checkhangup;
  707.     case ord(c) of
  708.       32..126:if (cp<79) then begin
  709.                 i[cp]:=c; cp:=cp+1; outkey(c);
  710.               end;
  711.       127,8:if cp>1 then begin c:=chr(8);
  712.                prompt(c+' '+c); cp:=cp-1;
  713.             end;
  714.       26:phelp;
  715.       24:begin
  716.            for cv:=1 to cp-1 do prompt(chr(8)+' '+chr(8)); cp:=1;
  717.          end;
  718.        7:o(#7);
  719.       23:if cp>1 then repeat
  720.            prompt(chr(8)+' '+chr(8)); cp:=cp-1;
  721.          until (cp=1) or (i[cp]=' ');
  722.        9:begin
  723.            cv:=5-(cp mod 5); if (cp+cv<79)  then
  724.              for cc:=1 to cv do begin
  725.                prompt(' ');
  726.                i[cp]:=' '; cp:=cp+1;
  727.              end;
  728.          end;
  729.   end;
  730.   until (c=#13) or (cp=79) or hangup or (c=#196);
  731.   if c=#196 then begin c:=#13; ch:=false; end;
  732.   i[0]:=chr(cp-1);
  733.   if c<>chr(13) then begin
  734.     cv:=cp-1;
  735.     while (cv>0) and (i[cv]<>' ') and (i[cv]<>chr(8))do cv:=cv-1;
  736.     if (cv>(cp div 2)) and (cv<>cp-1) then begin
  737.       ll:=copy(i,cv+1,cp-cv); for cc:=cp-2 downto cv do prompt(chr(8));
  738.       for cc:=cp-2 downto cv do prompt(' ');
  739.       i[0]:=chr(cv-1);
  740.     end;
  741.   end;
  742.   nl;
  743. end;
  744.  
  745. procedure chat;
  746. var c,ohl:char; tf:boolean; sp,xx:str; x:integer; t,t1:real;
  747. begin
  748.   sp:=thisline; ch:=true; chatcall:=false; tf:=echo; echo:=true;nl;nl; t:=timer;
  749.   thisuser.option:=thisuser.option-[alert]; ohl:=helpl; helpl:=#0;
  750.   print('Sysop''s here...'); nl;
  751.   if chatr<>'' then begin
  752.     writeln; writeln; writeln('Reason: ',chatr); writeln; writeln; chatr:='';
  753.   end;
  754.   repeat
  755.     inli1(xx);
  756.     if (xx='/quitchat') or (xx='/QUITCHAT') then begin
  757.       t1:=timer; while (abs(t1-timer)<4.0) and (not keypressed) do;
  758.       if not keypressed then ch:=false;
  759.     end else if cfo then writeln(cf,xx);
  760.   until (not ch) or hangup;
  761.   nl;print('Chat mode over...'); nl;
  762.   extratime:=extratime+timer-t; ch:=false; echo:=tf;
  763.   if hangup and cfo then begin
  764.     writeln(cf); writeln(cf,'<HANGUP>');
  765.   end;
  766.   prompt(sp); thisline:=sp;
  767.   if cfo then begin cfo:=false; close(cf); end;
  768.   helpl:=ohl;
  769. end;
  770.  
  771. function yn:boolean;
  772. var c:char;
  773. begin
  774.   if not hangup then begin
  775.     repeat
  776.       getkey(c);
  777.       if c=#26 then phelp;
  778.       skey(c);
  779.       c:=upcase(c);
  780.     until (c='Y') or (c='N') or (c=chr(13)) or hangup;
  781.     if c='Y' then begin print('Yes'); yn:=true; end else begin print('No'); yn:=false; end;
  782.     if hangup then yn:=false;
  783.   end;
  784. end;
  785.  
  786. procedure input1(var i:str; ml:integer; tf:boolean);
  787. var cp:integer;
  788.     c:char;
  789.     r:real;
  790. begin
  791.  checkhangup;
  792.  if not hangup then begin
  793.   r:=timer;
  794.   cp:=1;
  795.   repeat
  796.     getkey(c);
  797.     skey(c);
  798.     if c=#26 then phelp;
  799.     if c=#196 then r:=timer;
  800.     if not tf then c:=upcase(c);
  801.     if (c>=' ') and (c<chr(127)) then
  802.       if cp<=ml then begin
  803.       i[cp]:=c;
  804.       cp:=cp+1;
  805.       outkey(c);
  806.       thisline:=thisline+c;
  807.     end else else case ord(c) of
  808.       127,8:if cp>1 then begin
  809.                c:=chr(8);
  810.                outkey(c);outkey(' '); outkey(c);
  811.                cp:=cp-1;
  812.                if length(thisline)>0 then thisline:=copy(thisline,1,length(thisline)-1);
  813.              end;
  814.       21,24:while cp<>1 do begin
  815.                cp:=cp-1;
  816.                outkey(#8);outkey(' '); outkey(#8);
  817.                if length(thisline)>0 then thisline:=copy(thisline,1,length(thisline)-1);
  818.              end;
  819.     end;
  820.     if (timer-r)>300.0 then hangup:=true;
  821.   until (c=#13) or (c=#14) or hangup;
  822.   i[0]:=chr(cp-1);
  823.   nl;
  824.  end;
  825. end;
  826.  
  827. procedure input(var i:str; ml:integer);
  828. begin
  829.   input1(i,ml,false);
  830. end;
  831.  
  832.  
  833. procedure inputl(var i:str; ml:integer);
  834. begin
  835.   input1(i,ml,true);
  836. end;
  837.  
  838. function find(c:char; s:str):boolean;
  839. var i:integer; tf:boolean;
  840. begin
  841.   c:=upcase(c);
  842.   tf:=false;
  843.   for i:=1 to length(s) do
  844.     if c=upcase(s[i]) then tf:=true;
  845.   find:=tf;
  846. end;
  847.  
  848. procedure onek(var c:char; ch:str);
  849.  var i1,i:str; tf:boolean;
  850. begin
  851.   i1:=thisline; tf:=false;
  852.   repeat
  853.     if not(onekey in thisuser.defaults) then begin
  854.       if tf then prompt(i1);
  855.       input(i,3);
  856.       if length(i)=1 then c:=i[1] else c:=' ';
  857.     end else begin
  858.       getkey(c);
  859.       if c=#26 then phelp;
  860.       skey(c);
  861.       c:=upcase(c);
  862.     end;
  863.     tf:=true;
  864.   until find(c,ch) or hangup;
  865.   if not find(c,ch) then c:=ch[1];
  866.   if onekey in thisuser.defaults then print(''+c);
  867. end;
  868.  
  869. procedure centre(var i:str);
  870. begin
  871.   if pap<>0 then nl;
  872.   if i[1]=#2 then i:=copy(i,2,length(i)-1);
  873.   if length(i)<thisuser.linelen then
  874.     i:=copy('                                               ',1,
  875.       (thisuser.linelen-length(i)) div 2)+i;
  876. end;
  877.  
  878. procedure printa1(i:str; var abort,next:boolean);
  879. var c:integer; cc:char;
  880.  procedure wkey;
  881.  begin
  882.     while (not empty) and (not hangup) do begin
  883.       cc:=inkey; skey(cc);
  884.       if (cc=' ') or (cc=chr(3)) or (cc=chr(24)) or (cc=chr(11)) then
  885.         abort:=true;
  886.       if (cc=chr(14)) then begin abort:=true; next:=true; end;
  887.       if (cc=chr(19)) or (cc='P') or (cc='p') then getkey(cc);
  888.     end;
  889.  end;
  890.  
  891. begin
  892.  checkhangup;
  893.  if not hangup then begin
  894.   abort:=false; next:=false; c:=1;
  895.   wkey;
  896.   while (not abort) and (c-1<>length(i)) and (not hangup) do begin
  897.     checkhangup;
  898.     if i[c]=chr(8) then pap:=pap-1 else if i[c]<>chr(10) then pap:=pap+1;
  899.     wkey;
  900.     outkey(i[c]);
  901.     c:=c+1;
  902.   end;
  903.  end else abort:=true;
  904. end;
  905.  
  906. procedure printa(i:str; var abort,next:boolean);
  907. var s:str; p,lp,rp:integer;
  908. begin
  909.   abort:=false;
  910.   p:=1; rp:=0; lp:=1;
  911.   if i[1]=#2 then begin
  912.     if i[length(i)]=#1 then i:=copy(i,1,length(i)-1);
  913.     centre(i);
  914.     printa1(i,abort,next);
  915.     nl;
  916.   end else begin
  917.     while (p<=length(i)) and (not abort) and (not hangup) do begin
  918.       rp:=0;
  919.       while (i[p]<>' ') and (p<=length(i)) and (not hangup) do begin
  920.         if i[p]=chr(8) then rp:=rp-1 else
  921.           if (i[p]<>#10) and (i[p]<>#1) then rp:=rp+1;
  922.         p:=p+1;
  923.       end;
  924.       if i[p]=' ' then rp:=rp+1;
  925.       s:=copy(i,lp,(p-lp+1)); p:=p+1; lp:=p;
  926.       if s[length(s)]=#1 then s:=copy(s,1,length(s)-1);
  927.       if s<>'' then if (copy(s,length(s),1)<>' ') and (i[length(i)]<>#1) then s:=s+' ';
  928.       if (pap+rp>=thisuser.linelen) then nl;
  929.       printa1(s,abort,next);
  930.     end;
  931.     if not abort then printa1('',abort,next);
  932.     if abort or (i[length(i)]=#1) or (length(i)=0) then nl;
  933.   end;
  934. end;
  935.  
  936. procedure printacr(i:str; var abort,next:boolean);
  937. begin
  938.  if not abort then
  939.   if i[length(i)]=#1 then
  940.     printa(i,abort,next)
  941.   else
  942.     printa(i+#1,abort,next);
  943. end;
  944.  
  945. procedure phelp;
  946. var i,lli:str; c:integer; abort,next:boolean;
  947. begin
  948.   ihelp:=true;
  949.   lli:=thisline;
  950.   if helpl in ['0'..'^'] then
  951.     if helpi[helpl]>0 then begin
  952.       cls;
  953.       c:=helpi[helpl];
  954.       i:=''; abort:=false;
  955.       while (help[c]<>'|') and (not abort) do begin
  956.         if help[c]=#10 then begin
  957.           printacr(i,abort,next);
  958.           i:='';
  959.         end else
  960.           if help[c]<>#13 then
  961.             i:=i+help[c];
  962.         c:=c+1;
  963.       end;
  964.       nl; nl; nl;
  965.       prompt(lli);
  966.     end;
  967.   ihelp:=false;
  968. end;